﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using System.ComponentModel;

namespace ReporterEngine.Model
{
    public abstract class BaseInstanceNode : INotifyPropertyChanged
    {
        public XElement Element { get; set; }
        public CIFModel Model { get; set; }

        public bool IsLoading
        {
            get { return _isLoading; }
            set
            {
                if (this._isLoading != value)
                {
                    this._isLoading = value;
                    this.NotifyPropertyChanged("IsLoading");
                }
            }
        }

        public virtual string GetCompareName()
        {
            if(this is InstanceNode)
            {
                var iNode = this as InstanceNode;
                return iNode.InstanceName;
            }

            if (this is InstanceReference)
            {
                var iNode = this as InstanceReference;
                return iNode.PropertyName + iNode.ReferenceNode.InstanceName;
            }

            if (this is InstanceUsedBy)
            {
                var iNode = this as InstanceUsedBy;
                return iNode.PropertyName + iNode.UsedByNode.InstanceName;
            }

            if (this is InstanceProperty)
            {
                var iNode = this as InstanceProperty;
                return iNode.PropertyName;
            }
            
            return null;
        }

        private bool _isLoading = false;


        #region INotifyPropertyChanged Members

        public event PropertyChangedEventHandler PropertyChanged;

        protected void NotifyPropertyChanged(string propertyName)
        {
            if (this.PropertyChanged != null)
            {
                this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }

        #endregion
    }
}
